package com.robot.system.controller;

import com.robot.common.core.domain.Query;
import com.robot.common.core.tool.PageTransform;
import com.robot.common.core.tool.R;
import com.robot.common.core.tool.WrapperTransform;
import com.robot.system.domain.entity.SysUser;
import com.robot.system.service.ISysUserService;
import com.robot.utils.ListUtil;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;



/**
 * @Description:TODO
 * @author:qzg
 * @Date:2021-01-30 9:27
 */
@RestController
@RequestMapping("/user")
@AllArgsConstructor
public class UserController {

    private ISysUserService sysUserService;

    /**
     * 分页查询
     * @param query 分页信息，current-当前页，size-每页条数
     * @param sysUser 实体类
     * @return
     */
    @GetMapping("/page")
    public R page(Query query,SysUser sysUser){
        return R.data(sysUserService.page(PageTransform.getPage(query), WrapperTransform.getDefuatWrapper(sysUser)));
    }

    /**
     * 自定义分页查询
     * @param query 分页信息，current-当前页，size-每页条数
     * @param sysUser 实体类
     * @return
     */
    @GetMapping("/getPage")
    public R getPage(Query query,SysUser sysUser){
        return R.data(sysUserService.getPage(PageTransform.getPage(query),sysUser));
    }

    /**
     * 查询列表
     * @param sysUser 实体类
     * @return
     */
    @GetMapping("/list")
    public R list(SysUser sysUser){
        return R.data(sysUserService.list(WrapperTransform.getDefuatWrapper(sysUser)));
    }

    /**
     * 查询单条信息
     * @param sysUser 实体类，请传唯一值
     * @return
     */
    @GetMapping("/detail")
    public R detail(SysUser sysUser){
        return R.data(sysUserService.getOne(WrapperTransform.getDefuatWrapper(sysUser)));
    }

    /**
     * 保存信息
     * @param sysUser 实体类
     * @return
     */
    @PostMapping("/save")
    public R save(@RequestBody SysUser sysUser){
        return R.status(sysUserService.save(sysUser));
    }

    /**
     * 更新信息
     * @param sysUser
     * @return
     */
    @PutMapping
    public R update(@RequestBody SysUser sysUser){
        return R.status(sysUserService.updateById(sysUser));
    }

    /**
     * 删除信息
     * @param ids
     * @return
     */
    @DeleteMapping("/{ids}")
    public R delete(@PathVariable String ids){
        return R.status(sysUserService.removeByIds(ListUtil.toLongList(ids,",")));
    }

}
